package com.woniu.order.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniu.core.util.JwtUtil;
import com.woniu.core.util.PageInfo;
import com.woniu.core.util.Result;
import com.woniu.order.dto.AdminOrderSearchDto;
import com.woniu.order.dto.TCourseOrderDto;
import com.woniu.order.form.AdminOrderSearchForm;
import com.woniu.order.form.UserRefundForm;
import com.woniu.order.model.TCourseOrder;
import com.woniu.order.service.TCourseOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 吴彦祖
 * @since 2024年04月02日
 */
@RestController
@RequestMapping("/tCourseOrder")
@Api(tags = "课程订单表相关接口")
public class TCourseOrderController {

    @Resource
    private TCourseOrderService tCourseOrderService;
    @GetMapping("/list.user/{userId}")
    @ApiOperation("用户查询自己的所有课程订单")
    public Result<List<TCourseOrderDto>> list(@PathVariable("userId") Integer userId) throws Exception {
        List<TCourseOrderDto> search = tCourseOrderService.search(userId);
        return Result.getListResult(TCourseOrderDto.class).setMsg("查询成功").setData(search);
    }

    @PostMapping("/list.admin")
    @ApiOperation("管理员分页查询或根据订单状态/场馆num/订单num查询所有课程订单")
    public Result<PageInfo> adminList(@RequestBody AdminOrderSearchForm form) throws Exception {
        PageInfo<AdminOrderSearchDto> search = tCourseOrderService.adminList(form);
        return Result.getResult(PageInfo.class).setMsg("查询成功").setData(search);
    }

    //退款
    @GetMapping("/refund.user")
    @ApiOperation("用户退款")
    public String refund(UserRefundForm form) throws Exception{
        Integer userId = JwtUtil.getUserId(2);
        form.setUserId(userId);
        tCourseOrderService.refund(form);
        return "退款成功";
    }


}

